﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LCRReader
{
    public partial class frmConfig : Form
    {
       public int idUpdate = 0;
        TestConfigAccess _db = new TestConfigAccess();
        public event Action Update;
        public frmConfig()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            float value1 = float.NaN;
            float value2 = float.NaN;
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("测试项目不能为空");
                return;
            }
            if (!float.TryParse(this.textBox2.Text, out value1))
            {
                MessageBox.Show("上限值格式一定为浮点数");
                return;
            }
            if (!float.TryParse(this.textBox3.Text, out value2))
            {
                MessageBox.Show("下限值格式一定为浮点数");
                return;
            }
            if (textBox4.Text == "")
            {
                MessageBox.Show("测试指令不能为空");
                return;
            }
            if (Text=="设置")
            {
                TestConfig testConfig = new TestConfig { Enable =checkBox1.Checked, Lower = value2, Upper = value1, Name = this.textBox1.Text, CMD = this.textBox4.Text };

                long id = _db.Insert(testConfig);
                if (Update != null)
                    Update();
                this.Close(); 
            }
            else if(Text=="编辑")
            {   
                
                TestConfig testConfig = new TestConfig { Enable =checkBox1.Checked, Lower = value2, Upper = value1, Name = this.textBox1.Text, CMD = this.textBox4.Text };
                long id = _db.Update(testConfig,idUpdate);
                if (Update != null)     
                    Update();
                this.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

